#ifndef DRIVER_USART_H
#define DRIVER_USART_H
#include <termios.h> /* POSIX terminal control definitions */
#include <vector>
#include "stdio.h"
#include <errno.h> /* Error number definitions */
#include <fcntl.h> /* File control definitions */
#include <stdio.h>
#include <string.h>
#include <termios.h> /* POSIX terminal control definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <poll.h>

#include <fcntl.h>
#include <linux/serial.h>
#include <poll.h>
#include <sys/ioctl.h>

#include <iostream>
#include <vector>

//namespace mower_driver {


#define REV_NULL 0
#define REV_TIOMEOUT -1
#define REV_ERROR -2
#define REV_TRUE -3
#define RECV_DONE -4

#define  BPS57600    0010001
#define  BPS115200   0010002
#define  BPS230400   0010003
#define  BPS460800   0010004
#define  BPS500000   0010005
#define  BPS576000   0010006
#define  BPS921600   0010007
#define  BPS1000000  0010010
#define  BPS1152000  0010011
#define  BPS1500000  0010012
#define  BPS2000000  0010013
#define  BPS2500000  0010014
#define  BPS3000000  0010015
#define  BPS3500000  0010016
#define  BPS4000000  0010017

#define SERIALDRIVER_OPEN 0
#define SERIALDRIVER_CLOSE 1
#define SERIALDRIVER_ERROR 2

typedef struct
{
  uint8_t rev_buf[512];
  uint32_t recv_len;
}Usart_Buf;

class SerialDriver {
public:
    int32_t SerialDriver_state;

    SerialDriver(const char *_path, speed_t _speed);
    ~SerialDriver();
    int ReadBytesBlock(uint8_t *rev_buf, int rev_len, int time);
    //int ReadBuf(uint8_t *rev_buf, int rev_len, int timeout);
    int32_t ReadBytes(std::vector<uint8_t>& output, size_t max_bytes, int32_t timeout);
    int ReadBuf(Usart_Buf & usartBuf, int timeout);
    int Write(const std::vector<uint8_t>& input);
    int Write(const std::string& _input) ;
    int Write(uint8_t *pinput, uint32_t pinput_size);
private:
    int fd;
    std::string serial_path;
};

//}

#endif